package work.xiaohong.gupiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import work.xiaohong.gupiao.dao.YinhangMapper;
import work.xiaohong.gupiao.pojo.Yinhang;
import work.xiaohong.gupiao.service.YinhangService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class YinhangServiceImpl implements YinhangService {

    @Autowired
    private YinhangMapper yinhangMapper;


    /**
     * 条件+分页查询Yinhang
     * @param yinhang 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<Yinhang> findPage(Yinhang yinhang, int page, int size){
        // 构建查询条件
        QueryWrapper<Yinhang> queryWrapper = new QueryWrapper<Yinhang>(yinhang);
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return yinhangMapper.selectPage(pg, queryWrapper);
    }

    /**
     * 分页查询Yinhang
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<Yinhang> findPage(int page, int size){
        // 构建分页
        Page pg = new Page(page, size);
        // 分页查询
        return yinhangMapper.selectPage(pg, null);
    }

    /**
     * 多条件搜索方法Yinhang
     * @param yinhang
     * @return
     */
    @Override
    public List<Yinhang> findList(Yinhang yinhang){
        // 构建查询条件
        QueryWrapper<Yinhang> queryWrapper = new QueryWrapper<Yinhang>(yinhang);
        // 查询数据
        return yinhangMapper.selectList(queryWrapper);
    }

    /**
     * 根据ID删除Yinhang
     * @param id
     */
    @Override
    public void delete(Integer id){
        yinhangMapper.deleteById(id);
    }

    /**
     * 根据ID修改Yinhang
     * @param yinhang
     */
    @Override
    public void update(Yinhang yinhang){
        yinhangMapper.updateById(yinhang);
    }

    /**
     * 增加Yinhang
     * @param yinhang
     */
    @Override
    public void add(Yinhang yinhang){
        yinhangMapper.insert(yinhang);
    }

    /**
     * 根据ID查询Yinhang
     * @param id
     * @return
     */
    @Override
    public Yinhang findById(Integer id){
        return  yinhangMapper.selectById(id);
    }

    /**
     * 查询全部Yinhang数据
     * @return
     */
    @Override
    public List<Yinhang> findAll() {
        return yinhangMapper.selectList(null);
    }
}
